package com.tools.common.beans.vo;

import lombok.Data;

/**
 * 处理返回数据
 *
 * @author 道剑仙
 * 2022/1/8 - 20:50
 */
@Data
public class Result<T> {
    /**
     * 状态码
     */
    private int code = 0;

    /**
     * 提示消息
     */
    private String message = "";

    /**
     * 数据
     */
    private T data;

    /**
     * 记录数
     */
    private int count;

    /**
     * 是否成功
     */
    private boolean success;


    /**
     * 构造方法
     *
     * @param data
     */
    private Result(T data) {
        this.code = 0;
        this.success = true;
        this.message = "成功";
        this.data = data;
    }

    private Result() {
        this.code = 0;
        this.success = true;
        this.message = "成功";
    }

    /**
     * 成功
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> OK(T data) {
        return new Result<T>(data);
    }

    public static <T> Result<T> OK() {
        return new Result<T>();
    }

    public static <T> Result<T> Tip(String message, int code) {
        Result<T> result = new Result<T>(null);
        result.setMessage(message);
        result.setCode(code);
        if (code != 0){
            result.setSuccess(false);
        }
        return result;
    }
}
